

namespace Stee.CAP8.MessageBus.Interface.Models
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// Message for event publishing
    /// </summary>
    [Serializable]
    public class EventMessage
    {
        /// <summary>
        /// Gets or sets the mesage subscription topic
        /// </summary>
        public string Action { get; set; }

        /// <summary>
        /// Gets or sets the correlation ID
        /// </summary>
        public string CorrelationID { get; set; }

        /// <summary>
        /// Gets or sets the client ID
        /// </summary>
        public string ClientID { get; set; }

        /// <summary>
        /// Gets the command message source
        /// </summary>
        public string Source { get; set; }

        /// <summary>
        /// Gets or sets the JSON web token (JWT)
        /// </summary>
        public string JWT { get; set; }

        /// <summary>
        /// Gets or sets the command creation date time
        /// </summary>
        public DateTime CreateDT { get; set; }

        /// <summary>
        /// Gets or sets the message data/content
        /// </summary>
        public byte[] Data { get; set; }

        /// <summary>
        /// Gets the header collection mappings
        /// </summary>
        public Dictionary<string, object> Headers { get; private set; }


        /// <summary>
        /// Initializes a new instance of the CommandMessage class
        /// </summary>
        public EventMessage()
        {
            this.Headers = new Dictionary<string, object>();
        }


        /// <summary>
        /// Add new header referenced by key.
        /// If key already exist, current value will be over-written.
        /// </summary>
        /// <param name="key">Identifier for header value</param>
        /// <param name="value">Header object</param>
        /// <returns>Return TRUE if added else FALSE</returns>
        public bool AddHeader(string key, object value)
        {
            this.Headers[key] = value;
            return true;
        }

        /// <summary>
        /// Remove existing header by key
        /// </summary>
        /// <param name="key">Identifier for header value</param>
        /// <returns>Return TRUE if removed else FALSE</returns>
        public bool RemoveHeader(string key)
        {
            return this.Headers.Remove(key);
        }

        /// <summary>
        /// Check for existing header key
        /// </summary>
        /// <param name="key">Identifier for header value</param>
        /// <returns>Return TRUE if </returns>
        public bool IsHeaderExist(string key)
        {
            return this.Headers.ContainsKey(key);
        }

        /// <summary>
        /// Get the header object by key identifier
        /// </summary>
        /// <param name="key">Key identifier</param>
        /// <returns>Return header object if found else NULL</returns>
        public object GetHeaderByKey(string key)
        {
            return this.IsHeaderExist(key) ? this.Headers[key] : null;
        }

        /// <summary>
        /// Gets the header mappings
        /// </summary>
        /// <returns>Return header mappings</returns>
        public Dictionary<string, object> GetAllHeaders()
        {
            return new Dictionary<string, object>(this.Headers);
        }
    }
}
